﻿using System;
using System.Collections.Generic;
using NapazEngine.Framework.Messages;

namespace NapazEngine.Framework
{
    /// <summary>
    /// An Observer pattern class to serve as a basis 
    /// for following framework elements
    /// </summary>
    public class FrameworkElement
    {
        protected List<FrameworkElement> subscribers;

        public FrameworkElement()
        {
            subscribers = new List<FrameworkElement>();
        }

        /// <summary>
        /// Notify this framework element of something through a GameMessage
        /// </summary>
        /// <param name="message"></param>
        public virtual void Notify(GameMessage message)
        {
            throw new NotImplementedException("This method must be overridden and superclass FrameworkElement.Notify() must not be used");
        }

        /// <summary>
        /// Registers a framework element to receive notifications
        /// </summary>
        /// <param name="element"></param>
        public virtual void Register(FrameworkElement element)
        {
            subscribers.Add(element);
        }

        /// <summary>
        /// Unregisters a framework element to receive notifications
        /// </summary>
        /// <param name="element"></param>
        public virtual void Unregister(FrameworkElement element)
        {
            subscribers.Remove(element);
        }
    }
}
